<template>
  <div>
    <RouterView />
  </div>
</template>

<script lang="ts" setup>
import { routerStore } from './stores/counter'
import { useRouter,useRoute } from 'vue-router'
import Main from '@/views/MainView.vue'
import Student from '@/views/StudentView.vue'
import Leave from '@/views/LeaveView.vue'
import addLeave from '@/views/AddLeave.vue'
import dataanalysis from  "@/views/DataAnalysis.vue"

let routerInfo: any = {
  student: Student,
  leave: Leave,
  addleave: addLeave,
  dataanalysis
}
let $router = useRouter()
let $route = useRoute();
let $store = routerStore()

let routerList: any = window.localStorage.getItem('routerList')

if (routerList) {
  console.log('加载')
  routerList = JSON.parse(routerList)
  $router.removeRoute('main')
  $router.addRoute({
    path: '/main',
    name: 'main',
    component: Main
  })

  let defaultRouter = routerList[0]
  $router.addRoute('main', { path: '', component: routerInfo[defaultRouter.com] })

  routerList.forEach((element: any) => {
    $router.addRoute('main', {
      name: element.path,
      path: element.path,
      component: routerInfo[element.com]
    })
  })
  $store.initMenuList(routerList);
  console.log($router.getRoutes());
  console.log($route.path);
  $router.push(window.location.hash.split("#")[1]);
  // $router.push($route.path);
}
</script>
